package com.Jeu;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class ModeGame extends Activity {
	public static int modeTime = 20;
	private SharedPreferences pref;
	public static int check = 2;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.modegame);
		RadioGroup rGroup = (RadioGroup) findViewById(R.id.radio_group1);

		OnClickListener radio_listener = new OnClickListener() {
			public void onClick(View v) {
				onRadioButtonClick(v);
			}
		};

		RadioButton button1 = new RadioButton(this);
		// RadioButton button1 = (RadioButton) findViewById(R.id.radio1);
		button1.setText(R.string.rad_easy);
		button1.setTextColor(Color.RED);
		button1.setOnClickListener(radio_listener);
		rGroup.addView(button1);

		OnClickListener radio_listener1 = new OnClickListener() {
			public void onClick(View v) {
				onRadioButtonClick1(v);
			}
		};

		RadioButton button2 = new RadioButton(this);
		// RadioButton button2 = (RadioButton) findViewById(R.id.radio2);
		button2.setText(R.string.rad_normal);
		button2.setTextColor(Color.GREEN);
		button2.setOnClickListener(radio_listener1);
		rGroup.addView(button2);

		OnClickListener radio_listener2 = new OnClickListener() {
			public void onClick(View v) {
				onRadioButtonClick2(v);
			}
		};

		RadioButton button3 = new RadioButton(this);
		// RadioButton button3 = (RadioButton) findViewById(R.id.radio3);
		button3.setText(R.string.rad_hard);
		button3.setTextColor(Color.BLUE);
		button3.setOnClickListener(radio_listener2);
		rGroup.addView(button3);

		pref = getSharedPreferences("checkPrf", MODE_PRIVATE);
		check = pref.getInt("check", check);
		Toast.makeText(ModeGame.this, check + "test", Toast.LENGTH_SHORT)
				.show();
		if (check == 1)
			rGroup.check(button1.getId());
		if (check == 2)
			rGroup.check(button2.getId());
		if (check == 3)
			rGroup.check(button3.getId());

	}

	public void onRadioButtonClick(View v) {
		check = 1;
		pref = getSharedPreferences("checkPrf", MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		editor.putInt("check", check);
		editor.commit();
		setTime(60);
		RadioButton button = (RadioButton) v;
		Toast.makeText(ModeGame.this, button.getText() + " was chosen.",
				Toast.LENGTH_SHORT).show();
	}

	public void onRadioButtonClick1(View v) {
		check = 2;
		pref = getSharedPreferences("checkPrf", MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		editor.putInt("check", check);
		editor.commit();
		setTime(40);
		RadioButton button = (RadioButton) v;
		Toast.makeText(ModeGame.this, button.getText() + " was chosen.",
				Toast.LENGTH_SHORT).show();
	}

	public void onRadioButtonClick2(View v) {
		check = 3;
		pref = getSharedPreferences("checkPrf", MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		editor.putInt("check", check);
		editor.commit();
		setTime(20);
		RadioButton button = (RadioButton) v;
		Toast.makeText(ModeGame.this, button.getText() + " was chosen.",
				Toast.LENGTH_SHORT).show();
	}

	public int getTime() {
		return modeTime;
	}

	public void setTime(int sTime) {
		modeTime = sTime;
	}
}